home *** CD-ROM | disk | FTP | other *** search
/ Mac Cube 4: Multimedia Applications / MacCube Volume 4: Multimedia Applications.iso / Graphics / NIH Image Folder / Macros / Line Plots->Data < prev    next >
Text File  |  1993-07-29  |  3KB  |  124 lines

  1. macro 'Convert Line Plot to Points [C]';
  2. {
  3. Requires a binary image conatining a black plot on a white
  4. background. Select the plot before running this macro. It may be
  5. necessary to increase Max Measurements in Options.
  6. }
  7. var
  8.   left,top,width,height,i,nPixels,mean,mode,min,max:integer;
  9. begin
  10.   RequiresVersion(1.45);
  11.   Measure;
  12.   GetResults(nPixels,mean,mode,min,max)
  13.   if (histogram[0]+histogram[255])<>nPixels then begin
  14.     PutMessage('This macro only works on binary images.');
  15.     exit;
  16.   end;
  17.   if histogram[0]<histogram[255] then begin
  18.     PutMessage('This macro requires a black plot on a white background.');
  19.     exit;
  20.   end;
  21.   SaveState;
  22.   GetRoi(left,top,width,height);
  23.   if width=0 then begin
  24.     PutMessage('Please select the line plot.');
  25.     exit;
  26.   end;
  27.   Duplicate('Particles');
  28.   i:=0;
  29.   SetForegroundColor(0);
  30.   SetLineWidth(1);
  31.   repeat
  32.     MoveTo(i,0);
  33.     LineTo(i,height);
  34.     i:=i+2;
  35.   until i>width;
  36.   RotateRight(true);
  37.   MeasureArea(false);
  38.   MeasureDensity(false);
  39.   MeasureXY(true);
  40.   LabelParticles(false);
  41.   SetParticleSize(1,999999);
  42.   InvertY(false);
  43.   AnalyzeParticles;
  44.   RestoreState;
  45. end;
  46.  
  47.  
  48. macro 'Plot Points [P]';
  49. {
  50. Plots the data points contained in the X and Y results columns. Note
  51. that X and Y are reversed because Analyze Particles scans from top
  52. to bottom, not left to right.
  53. }
  54. var
  55.   xmin,xmax,ymin,ymax,i,xscale,yscale:real;
  56.   width,height,margin,pwidth,pheight:integer;
  57. begin
  58.   SaveState;
  59.   margin:=40;
  60.   width:=500;
  61.   height:=300;
  62.   xmin:=999999;
  63.   xmax:=-999999;
  64.   ymin:=999999;
  65.   ymax:=-999999;
  66.   for i:=1 to rCount do begin
  67.     if rX[i]<xmin then xmin:=rX[i];
  68.     if rX[i]>xmax then xmax:=rX[i];
  69.     if rY[i]<ymin then ymin:=rY[i];
  70.     if rY[i]>ymax then ymax:=rY[i];
  71.   end;
  72.   SetNewSize(width,height);
  73.   SetForeground(255);
  74.   SetBackground(0);
  75.   MakeNewWindow('Plot');
  76.   pwidth:=width-2*margin;
  77.   pheight:=height-2*margin;
  78.   xscale:=pheight/(xmax-xmin);
  79.   yscale:=pwidth/(ymax-ymin);
  80.   SetForeground(255);
  81.   SetBackground(0); 
  82.   MoveTo(margin,margin);
  83.   for i:=1 to rCount do begin
  84.     LineTo(margin+(rY[i]-ymin)*yscale,margin+(rX[i]-xmin)*xscale);
  85.   end;
  86.   MakeRoi(margin,margin,pwidth+1,pheight+2);
  87.   MoveTo(margin,margin);
  88.   LineTo(margin+pwidth,margin);
  89.   MoveTo(margin,margin);
  90.   LineTo(margin,margin+pheight);
  91.   FlipVertical;
  92.   KillRoi;
  93.   SetFont('Geneva');
  94.   SetFontSize(9);
  95.   SetText('Centered');
  96.   MoveTo(margin+4,margin+pheight+12);
  97.   writeln(ymin:1:2);
  98.   MoveTo(margin+pwidth,margin+pheight+12);
  99.   writeln(ymax:1:2);
  100.   SetText('Right Justified');
  101.   MoveTo(margin-2,margin+pheight-5);
  102.   writeln(xmin:1:2);
  103.   MoveTo(margin-2,margin);
  104.   writeln(xmax:1:2);
  105.   RestoreState;
  106. end;
  107.  
  108.  
  109. macro 'Clear Outside [O]'
  110.  {Outline the line plot with the wand tool and then use this macro to}
  111.  {erase everything else.}
  112. begin
  113.   Copy;
  114.   SelectAll;
  115.   Clear;
  116.   RestoreRoi;
  117.   Paste;
  118.   KillRoi;
  119. end;
  120.  
  121.  
  122.  
  123.  
  124.